/*
 * @Author: LG
 * @Date: 2021-04-22 10:06:00
 * @Description: 
 * @Last Modified By: liu.guo
 * @Last Modified Time: 2021-04-22 10:07:44
 */
import axios,{AxiosInstance,AxiosRequestConfig,AxiosResponse,} from 'axios'
import Qs from 'qs'
const AjaxInstance:AxiosInstance = axios.create({
  baseURL:'https://10.202.94.100',
  timeout:3000,
  validateStatus:status=>status>=200&&status<300
})
AjaxInstance.interceptors.request.use((config:AxiosRequestConfig)=>{
  config.headers.Authorization=sessionStorage.getItem('token')??'Basic Y2xpZW50YXBwOjEyMw=='
  console.log(config)
  return config
})
AjaxInstance.interceptors.response.use((response:AxiosResponse)=>{
  const {data,status} = response
  if(status===200){
    return data
  }
  return 
},(error:Error)=>error)
export const GET = (url:string,data={},headers={})=>{
  headers = Object.assign({}, { headers: {} }, headers)
  return AjaxInstance.get(encodeURI(url+Qs.stringify(data)),headers)
}
export const POST = (url:string,data:any,headers={})=>{
  headers = Object.assign({}, { headers: {} }, headers)
  return AjaxInstance.post(encodeURI(url),Qs.stringify(data),headers)
}
export const PUT=(url:string,data={},headers={})=>{
  headers = Object.assign({}, { headers: {} }, headers)
  return AjaxInstance.put(encodeURI(url),data,headers)
}
export const PATCH = (url:string,data={},headers={})=>{
  headers = Object.assign({}, { headers: {} }, headers)
  return AjaxInstance.patch(encodeURI(url),data,headers)
}
export const DELETE = (url:string,headers={})=>{
  headers = Object.assign({}, { headers: {} }, headers)
  return AjaxInstance.delete(encodeURI(url),headers)
}